function ImageCvter() {
    this.dir = '/home/leo';
    this.full_num = 0;
    this.processed_num = 0;
    this.is_started_processing = false;
    this.timer = {};
    this.location = '/process_status';
    // this.trigger_cvt()
}

ImageCvter.prototype = {
    set_attr: function (dir, full_num, process_num) {
        this.dir = dir;
        this.full_num = full_num;
        this.processed_num = process_num;

    },
    set_html_stauts: function (set_str) {
        document.getElementById("process_status").innerHTML = set_str;
    },
    get_cvt_status: function (im_cvt_ptr) {
        // set html status
        console.log('get_cvt_status');
        $.ajax({
            type: "POST",
            url: im_cvt_ptr.location,
            dataType: "json",
            data: "requet processing status",
            success: function (data) {
                console.log('post success');
                console.log(data);
                im_cvt_ptr.set_html_stauts(" processing " + data['processed'] + "/" + data['full_num'])
                if (data['processed'] >= data['full_num']) {
                    im_cvt_ptr.stop_timer();
                }
            },
            error: function (e) {
                console.log("post error:");
                console.log(e)
            }
        });
    },
    trigger_cvt: function () {
        ptr = this
        this.timer = window.setInterval(function () {
            ptr.get_cvt_status(ptr);
        }, 1000);
    },
    stop_timer: function () {
        window.clearTimeout(this.timer)
    },
};

